package com.neu.controller;


import com.neu.domain.Activity;
import com.neu.service.ActivityService;
import com.neu.utils.ResultModel;

import com.neu.vo.ActivityVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/activity")
public class ActivityController {
    @Autowired
    ActivityService activityService;

    /**
     * 抢优惠卷
     * @param activityId
     * @param customerId
     * @return
     */
    @GetMapping("/{activityId}/skill")
    public ResultModel skill(@PathVariable("activityId") int activityId , int customerId){
        ResultModel resultModel=new ResultModel();
        String result= activityService.skill(activityId,customerId);
        resultModel.setData(result);
        resultModel.setMsg("抢优惠卷成功！");
        return  resultModel;
    }


    /**
     * 添加活动
     * @param activity
     * @return
     */
    @PostMapping("/add")
    public ResultModel<Integer> add(Activity activity){
        ResultModel resultModel=new ResultModel();

        resultModel.setData(activityService.add(activity));
        resultModel.setMsg("添加活动成功！");
        return  resultModel;
    }

    /**
     * 查找活动详情
     * @return
     */
    @GetMapping("/list")
    public ResultModel<List<ActivityVO>> find(){
        ResultModel resultModel=new ResultModel();
        List<ActivityVO> activityVOList=activityService.find();

        resultModel.setData(activityVOList);
        resultModel.setMsg("查询活动成功！");
        return  resultModel;
    }



}
